package novel.common.test;

/**
 * Created by sutong on 2017/10/24.
 */
public class PublicBoxx {
    private int apple = 0;

    public synchronized void increace() {
        while (apple ==5) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        apple++;
        System. out .println("生成苹果成功！苹果剩余个数"+apple );
        notify();
    }

    public synchronized void decreace() {
        while (apple ==0) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        apple--;
        System. out.println( "消费苹果成功！苹果剩余个数"+apple  );
        notify();
    }

    public static void main(String[] args) {
        PublicBoxx boxx=new PublicBoxx();
        new Thread(new Provider(boxx)).start();
        new Thread(new Consumer(boxx)).start();
    }
}
